package com.ujoku.controller.admin;


import com.labillusion.core.platform.web.rest.RESTController;
import com.ujoku.domain.admin.Parameter;
import com.ujoku.service.admin.ParametersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by suggestion on 2015/1/26.
 */
@RestController
public class ParametersMngController extends RESTController {

    @Autowired
    private ParametersService parametersService;

    @RequestMapping(value="/uj-admin/parameters/list", method = RequestMethod.GET)
    public List<Parameter> parametersList(){

        return parametersService.selectList();
    }

    @RequestMapping(value = "/uj-admin/parameters/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Parameter getById(@PathVariable String id){
        return (Parameter)parametersService.selectById(id);
    }

    @RequestMapping(value = "/uj-admin/parameters/add", method = RequestMethod.POST)
    @ResponseBody
    public Parameter add(@RequestBody Parameter parameter){
        parametersService.insert(parameter);
        return parameter;
    }

    @RequestMapping(value = "/uj-admin/parameters", method = RequestMethod.PUT)
    @ResponseBody
    public Parameter update(@RequestBody Parameter parameter){
        parametersService.update(parameter);
        return parameter;
    }

    @RequestMapping(value = "/uj-admin/parameters/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public String delete(@PathVariable int id){
        parametersService.deleteById(id);
        return "successfully";
    }
}
